﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace translator.Command
{
    public class TranslateSelectedStringByAPICommand : ICommand
    {
        MainWindow mainWindow;
        public TranslateSelectedStringByAPICommand(MainWindow mainWindow)
        {
            this.mainWindow = mainWindow;
        }

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public bool CanExecute(object parameter)
        {
            if (mainWindow.Datagrid.SelectedIndex == -1) { return false; }
            return true;
        }

        public void Execute(object parameter)
        {
            TranslateAPI translateAPI = Const.ToEnum<TranslateAPI>(parameter.ToString());
            if (mainWindow.Datagrid.SelectedIndex == -1) mainWindow.TranslateSelectedStringsByAPI(translateAPI);
            else CommandManager.InvalidateRequerySuggested();
        }
    }
}
